import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Locale;

/**
 * Created on 2022/1/17.
 *
 * @author Hou chaof
 */
public class Ex2 {
    //统计Java文件多少行
    public static long rows=0;
    public static  long filecount=0;

    public static void main(String[] args) {
        count(new File("F:\\IDEA\\maven-String"));
        System.out.println(rows);
        System.out.println(filecount);
        //System.out.printf("%s");
    }

    public static void count(File file){

        for (File t:file.listFiles()){
            //输出Java文件共有多少
            if (t.isDirectory()){
                count(t);
            }else if (t.getName().toLowerCase().endsWith(".java")){
                System.out.println(t.getAbsolutePath());
                System.out.println(rows(t));
                rows += rows(t);
                ++filecount;
            }
        }
    }


    public static long rows(File file) {
        long rows = 0;
        try {
            BufferedReader br = new BufferedReader(new FileReader(file));
            rows = br.lines().count();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return rows;
    }
}